﻿@{
    IList<Entity.BBC.DataRela> DataRelaList = ViewData["DataRelaList"] as IList<Entity.BBC.DataRela>;
}
<link href="~/Scripts/chosen/chosen.css" rel="stylesheet" />
<script src="~/Scripts/chosen/chosen.jquery.min.js"></script>
<script src="~/Scripts/chosen/chosen.proto.min.js"></script>

<div class="page">
    <!-- 标题栏 -->
    <header class="bar bar-nav">
        <h1 class='title'>添加采购数据</h1>
    </header>

    <!-- 工具栏 -->
    <nav class="bar bar-tab">
        <a class="tab-item" href="@Url.Action("Index", "Home")">
            <span class="icon icon-home"></span>
            <span class="tab-label">概览</span>
        </a>
        <a class="tab-item" href="@Url.Action("Index", "Product")">
            <span class="icon icon-app"></span>
            <span class="tab-label">商品</span>
        </a>
        <a class="tab-item" href="@Url.Action("Index", "Count")">
            <span class="icon icon-picture"></span>
            <span class="tab-label">采购统计</span>
        </a>
        <a class="tab-item active" href="@Url.Action("Index", "PurchaEdit")">
            <span class="icon icon-edit"></span>
            <span class="tab-label">采购填报</span>
        </a>
    </nav>

    <!-- 页面内容区 -->
    <div class="content">
        <div class="list-block">
            <ul>
                @*<li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">商品类别</div>
                            <div class="item-after">极致超薄型</div>
                        </div>
                    </div>
                </li>*@
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">商品类别</div>
                            <div class="item-input">
                                <select id="ddlProType" name="ddlProType">
                                    @if (ViewData["DDictionList1"] != null) { 
                                        foreach (var DDictionList1 in ViewData["DDictionList1"] as IList<Entity.BBC.DataDiction>)
                                        {
                                            <option value="@DDictionList1.Id">@DDictionList1.ValueDic</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">产地</div>
                            <div class="item-input">
                                <select id="ddlProAddress" name="ddlProAddress">
                                    @if (ViewData["DDictionList2"] != null)
                                    {
                                        foreach (var DDictionList2 in ViewData["DDictionList2"] as IList<Entity.BBC.DataDiction>)
                                        {
                                            <option value="@DDictionList2.Id">@DDictionList2.ValueDic</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">品种</div>
                            <div class="item-input">
                                @*<input id="txtVarieti" type="text" placeholder="">*@
                                <select id="txtVarieti" name="txtVarieti">
                                    @if (ViewData["DDictionList5"] != null)
                                    {
                                        foreach (var DDictionList5 in ViewData["DDictionList5"] as IList<Entity.BBC.DataDiction>)
                                        {
                                            <option value="@DDictionList5.ValueDic">@DDictionList5.ValueDic</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">采购价格</div>
                            <div class="item-input">
                                @*<input id="txtPurPrice" type="text" placeholder="¥0.00">*@
                                <input id="txtPurPrice" type="number" placeholder="¥0.00" pattern="[0-9]*">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">建议零售价</div>
                            <div class="item-input">
                                @*<input id="txtRetailPrice" type="text" placeholder="¥0.00" >*@
                                <input id="txtRetailPrice" type="number" placeholder="¥0.00" pattern="[0-9]*">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">上架时间</div>
                            <div class="item-input">
                                <input id="txtShelfTime" type="date" value="@DateTime.Now.ToString("yyyy-MM-dd")">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">下架时间</div>
                            <div class="item-input">
                                <input id="txtDownTime" type="date" value="@DateTime.Now.AddDays(7).ToString("yyyy-MM-dd")">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">商品周期</div>
                            <div class="item-input">
                                <input id="txtProCycle" type="text" placeholder="2个月">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">采购规格</div>
                            <div class="item-input">
                                <select id="ddlSpec" name="ddlSpec">
                                    @if (ViewData["DDictionList3"] != null)
                                    {
                                        foreach (var DDictionList3 in ViewData["DDictionList3"] as IList<Entity.BBC.DataDiction>)
                                        {
                                            <option value="@DDictionList3.Id">@DDictionList3.ValueDic</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">果品等级</div>
                            <div class="item-input">
                                <select id="ddlGrade" name="ddlGrade">
                                    @if (ViewData["DDictionList4"] != null)
                                    {
                                        foreach (var DDictionList4 in ViewData["DDictionList4"] as IList<Entity.BBC.DataDiction>)
                                        {
                                            <option value="@DDictionList4.Id">@DDictionList4.ValueDic</option>
                                        }
                                    }
                                </select>
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">建议采购量</div>
                            <div class="item-input">
                                @*<input id="txtPurNum" type="text" placeholder="1000">*@
                                <input id="txtPurNum" type="number" placeholder="1000" pattern="[0-9]*">
                            </div>
                        </div>
                    </div>
                </li>
                    
                <li>
                    <div class="item-content">
                        <div class="item-inner">
                            <div class="item-title label">果型</div>
                            <div class="item-input">
                                <input id="txtFruitType" type="text" placeholder="">
                            </div>
                        </div>
                    </div>
                </li>
                <li class="align-top">
                    <div class="item-title label" style="padding: 0px 0px 0px 15px">口感、卖点</div>
                    <div class="item-content">
                        <div class="item-inner">
                            @*<div class="item-title label">口感、卖点</div>*@
                            <div class="item-input">
                                @*<input id="txtPalate" type="text" placeholder="">*@
                                <textarea id="txtPalate" placeholder="" style="padding-top: 0rem;"></textarea>
                            </div>
                        </div>
                    </div>
                </li>
                <li class="align-top">
                    <div class="item-title label" style="padding: 0px 0px 0px 15px">产品特点知识</div>
                    <div class="item-content">
                        <div class="item-inner">
                            @*<div class="item-title label">产品特点知识</div>*@
                            <div class="item-input">
                                @*<input id="txtKnowled" type="text" placeholder="">*@
                                <textarea id="txtKnowled" placeholder="" style="padding-top: 0rem;"></textarea>
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="content-block">
            <div class="row">
                <div class="col-100"><a onclick="return SubmitVal();" class="button button-big button-fill button-success">提交</a></div>
                <script type="text/javascript">
                    function SubmitVal() {
                        var purPrice = $("#txtPurPrice").val();
                        var shelfTime = $("#txtShelfTime").val();
                        var varieti = $("#txtVarieti").val();
                        if (purPrice == "" || purPrice == null) {
                            $.alert("采购价格不能为空");
                            return false;
                        }
                        if (shelfTime == "" || shelfTime == null) {
                            $.alert("上架时间不能为空");
                            return false;
                        }
                        if (varieti == "" || varieti == null) {
                            $.alert("品种不能为空");
                            return false;
                        }
                        var proType = $("#ddlProType").val();
                        var proAddress = $("#ddlProAddress").val();
                        var proCycle = $("#txtProCycle").val();
                        var downTime = $("#txtDownTime").val();
                        var spec = $("#ddlSpec").val();
                        var palate = $("#txtPalate").val();
                        var grade = $("#ddlGrade").val();
                        var purNum = $("#txtPurNum").val();

                        var fruitType = $("#txtFruitType").val();
                        var retailPrice = $("#txtRetailPrice").val();
                        var knowled = $("#txtKnowled").val();

                        $.ajax({
                            async: false,
                            type: "post",
                            url: '@Url.Action("AddPruData")',
                            data: {
                                proType: proType,
                                proAddress: proAddress,
                                purPrice: purPrice,
                                shelfTime: shelfTime,
                                proCycle: proCycle,
                                downTime: downTime,
                                spec: spec,
                                palate: palate,
                                grade: grade,
                                purNum: purNum,
                                varieti: varieti,
                                fruitType: fruitType,
                                retailPrice: retailPrice,
                                knowled: knowled
                            },
                            success: function (result) {
                                if (result == "1") {
                                    $.alert("保存成功", function () {
                                        window.location.href = "@Url.Content("Index")";
                                    });
                                }
                                else {
                                    $.alert("保存失败");
                                    return false;
                                }
                            }
                        });
                    }
                </script>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            var config = {
                '.chosen-select': { search_contains: true },
                '.chosen-select-no-results': {no_results_text: '找不到数据!'}
            }
            for (var selector in config) {
                $("#ddlProType").chosen(config[selector]);
            }


            var PTID = $("#ddlProType").val();
            var PAID = $("#ddlProAddress").val()
            postChangeProType(PTID);
            postChangeProAddress(PTID, PAID);
            $("#ddlProType").change(function () {       // 商品类别改变事件
                var DDID = this.value;
                postChangeProType(DDID);
                var AddID = $("#ddlProAddress").val();
                postChangeProAddress(DDID, AddID)
            });

            $("#ddlProAddress").change(function () {    // 产地改变事件
                var PTID = $("#ddlProType").val();
                var DDID = this.value;
                postChangeProAddress(PTID, DDID);
            });
        });

        function postChangeProType(DDID) {
            $.ajax({
                async: false,
                type: "post",
                url: '@Url.Action("ChangeProType")',
                data: { DDID: DDID },
                success: function (result) {
                    $("#ddlProAddress").html("");
                    $.each(result, function (i, ProAddressList) {
                        $("#ddlProAddress").append($('<option></option>').val(ProAddressList.Id).html(ProAddressList.ValueDic));
                    });
                }
            });
        }

        function postChangeProAddress(DDID1, DDID2) {
            $.ajax({
                async: false,
                type: "post",
                url: '@Url.Action("ChangeProAddress")',
                data: { DDID1: DDID1, DDID2: DDID2 },
                success: function (result) {
                    $("#txtVarieti").html("");
                    $.each(result, function (i, VarietiList) {
                        $("#txtVarieti").append($('<option></option>').val(VarietiList.ValueDic).html(VarietiList.ValueDic));
                    });
                }
            });
        }
    </script>
</div>
